package com.song.controller.user;

import com.song.dto.ShoppingCartDTO;
import com.song.entity.ShoppingCart;
import com.song.result.Result;
import com.song.service.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user/shoppingCart")
public class ShopppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;
    //添加购物车
    @PostMapping("/add")
    public Result addCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
      log.info("添加购物车接口，参数为：{}",shoppingCartDTO);
        shoppingCartService.addCart(shoppingCartDTO);
      return Result.success(null,"购物车商品添加成功");
    }
    //查询购物车
    @GetMapping("/list")
    public Result<List<ShoppingCart>> getCartList(){
      log.info("查询购物车接口");
        List<ShoppingCart> cartList = shoppingCartService.getCartList();
      return Result.success(cartList,"查询购物车成功");
    }
    //清空购物车
    @DeleteMapping("/clean")
    public Result cleanCart(){
        log.info("清空购物车接口");
        shoppingCartService.cleanCart();
        return Result.success(null,"清空购物车成功");
    }
    //删除购物车中的一个商品
    @PostMapping("/sub")
    public Result subCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("删除购物车接口,参数：{}",shoppingCartDTO);
        shoppingCartService.subCart(shoppingCartDTO);
        return Result.success(null,"删除购物车成功");
    }
}
